#include <iostream>
#include "Socket.hpp" // 假设您的 Socket 类定义在 Socket.hpp 文件中
#include "../Log.hpp" // 假设您的日志记录宏定义在 Log.hpp 文件中
#include <cstring>

int main()
{
    Socket client;
    if (!client.CreateClient(8082, "127.0.0.1"))
    {
        std::cerr << "Failed to create client." << std::endl;
        return 1;
    }
    int num = 0;
    while (1)
    {
        const char *message = "Hello, server!";
        client.SendNonBlock(message, strlen(message));

        char buffer[1024];
        ssize_t recv_len = client.RecvNonBlock(buffer, sizeof(buffer));
        if (recv_len > 0)
        {
            std::cout << "Received from server: " << std::string(buffer, recv_len) << std::endl;
        }
        else
        {
            std::cerr << "Failed to receive from server." << std::endl;
        }
        sleep(1);
        num++;
        if (num == 5)
        {
            break;
        }
    }

    client.Close(); // 关闭客户端套接字
    return 0;
}